<template>
	<div class="container">
		<div class="jx-container">
      <div class="select-type">
        <div class="item">
          <span>账户类型</span>
          <div class="right">
            <span v-for="(item, index) in typelist" :key="index" :class="params_list.usertype == item ? 'active' : ''" @click="selected(item)">{{item}}</span>
          </div>
        </div>
        <div class="item">
          <span>交易类型</span>
          <div class="right">
            <span v-for="(item, index) in types" :key="index" :class="params_list.type == item ? 'active' : ''" @click="selected(item)">{{item}}</span>
          </div>
        </div>
        <div class="item table-item">
          <div class="right">
            <div class="item-inline">
              <span>用户名称</span>
              <el-input class="tel-value" v-model="params_list.username" placeholder="请输入用户名或手机号"></el-input>
            </div>
            <div class="item-inline">
              <span>流水来源</span>
              <el-input class="tel-value" v-model="params_list.no" placeholder="请输入流水编号"></el-input>
            </div>
            <div class="item-inline">
              <el-button class="jx-btn" type="primary" @click="search">搜索</el-button>
            </div>
          </div>
        </div>
      </div>
      <div class="jx-table">
        <div class="title">
          <img class="icon" src="/static/img/icon-platform.png"/>
          资金流水列表
          <div class="add-new">
            <el-button class="jx-btn" type="primary" :loading="boo.isExport" @click="exportRow">{{boo.isExport ? '请稍后……' : '导出'}}</el-button>
          </div>
        </div>
        <el-table :data="list" border style="width: 100%" v-loading="boo.loading">
          <el-table-column type="index" label="序列" width="60" align="center">
            <template slot-scope="scope">
              <span>{{(scope.$index + 1) + ((params_list.page - 1) * params_list.size)}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="accountInoutNo" label="资金流水编号" width="140" align="center" :show-overflow-tooltip="true">
            <!-- <template slot-scope="scope">
              <el-button @click="viewRow(scope.row)" type="text" size="small">{{scope.row.no}}</el-button>
            </template> -->
          </el-table-column>
          <el-table-column prop="accountCatalog" label="账户类型" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="accountName" label="账户名称" width="150" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="accountInoutCatalog" label="事项" width="150" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="accountInoutAt" label="交易时间" width="150" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="accountInoutSum" label="交易金额" align="center">
          </el-table-column>
          <el-table-column prop="accountInoutSource" label="交易来源" align="center">
          </el-table-column>
        </el-table>
        <div v-if="list.length != 0" class="jx-pagination">
           <el-pagination @current-change="pageChange" @size-change="handleSizeChange" :current-page="params_list.page" :page-sizes="[10,50,100]" :page-size="params_list.size" layout="total, sizes, prev, pager, next, jumper"
            :total="other.allRow">
          </el-pagination>
        </div>
      </div>
    </div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
        https: {
          list: this.$api.finance.funds,
          common: this.$api.common.dict
        },
        boo: {
          loading: false,
          isExport: false,
        },
        other: {
          allRow: 1,
        },
        list: '',
        params_list: {
          page: 1,
          size: 10,
          username: '',
          usertype: '全部',
          type: '全部',
          no: '',
        },
        typelist: '',
        types: '',
			}
		},
		mounted(){
      let _self = this
      _self.getList()
      _self.getDict('accountCatalog')
      _self.getDict('accountInoutCatalog')
    },
		methods: {
      getDict(type){
        let _self = this
        let params = {
          dictCode: type,
        }
        // 新建判断Map
        let actions = (i,list,)=>{
          return new Map([
            ['accountCatalog',()=>{
              _self.typelist = list
              _self.typelist.unshift('全部')
            }],
            ['accountInoutCatalog',()=>{
              _self.types = list
              _self.types.unshift('全部')
            }],
          ]).get(i).call(this)
        }
        let success = (res)=>{
          if(res.data.retCode == 1){
            actions(type,res.data.retObject)
          }else{
            _self.$message.error(res.data.retMsg)
          }
        }
        _self.$axios.get(_self.https.common, params, success) 
      },
      getList(){
        let _self = this
        let params = {
          pageNumber: _self.params_list.page,
          pageSize: _self.params_list.size,
          orderBy: '',
          accountCatalog: _self.params_list.usertype == '全部' ? '' : _self.params_list.usertype,
          accountInoutCatalog: _self.params_list.type == '全部' ? '' : _self.params_list.type,
          accountName: _self.params_list.username,
          accountInoutNo: _self.params_list.no,
        }
        _self.boo.loading = true
        let success = (res)=>{
          res = res.data
          if(res.retCode == 1){
            _self.list = res.retObject.list
            _self.other.allRow = Number(res.retObject.totalRow)
          }else{
            _self.$message.error(res.retMsg)
          }
          _self.boo.loading = false
        }
        _self.$axios.get(_self.https.list.list, params, success) 
      },
      selected(item){
        let _self = this
        _self.params_list.type = item.val
        _self.getList()
      },
      pageChange(val){
        let _self = this
        _self.params_list.page = val
        _self.getList()
      },
      handleSizeChange(val) {
        let _self = this
        _self.params_list.size = val
        _self.getList()
      },
      search(){
        let _self = this
      },
      exportRow(){

      },
    }
	}

</script>
<style scoped lang="sass">
  .select-type .table-item .right span
    width: 62px
</style>
